function [A, var_cov, prob_matrix] = TEST_Regimes_Estimation_No_Predictability

    tic
    
%Variables setup
    format long
    global m n number_parameters data_length returns;
    m = 3; % number or regimes
    n = 4; % number of risky assets time-series
    initial_row = 2;
    final_row = 856; 
    folder_db = '../db/';
    folder_result = '../Result/';
    FILE = 'Data.xlsx';
    TAB.Parameters = 'Parameters';
    TAB.Reported = 'Reported_Table';    
    diary(strcat(folder_result,'C_Regimes_Estimation_No_Predictability.txt'));
    diary off

%Read and adapt data in ascending date order
    filename_data = (strcat(folder_db,FILE));
    range = strcat('K', num2str(initial_row), ':', xlsColNum2Str(xlsColStr2Num({'K'})+ n - 1), num2str(final_row));
    temp = log(1+xlsread(filename_data, TAB.Parameters, range{1})); % We need to work with log-returns.
    if n ~= size(temp,2);
        error(strcat('The returns do not have the number of time-series as it should: ', num2str(n)))
    end
    returns = temp(end:-1:1,:); % Data in ascending date order.
    clear temp initial_row final_row range;
    
    data_length = size(returns,1);
   
    number_parameters = m*n + m*n*(n+1)/2 + m*(m-1);
    
    range = strcat('L', num2str(4 + n), ':', xlsColNum2Str(xlsColStr2Num({'L'})+ n - 1), num2str(3 + n + m));
    A = xlsread(filename_data, TAB.Reported, range{1})';
    var_cov = zeros(n,n,m);
    parfor reg =1:m 
       range = strcat('L', num2str(4 + m + reg*(n+1)), ':', xlsColNum2Str(xlsColStr2Num({'L'})+ n - 1), num2str(3 + n + m  + reg*(n+1)));
       var_cov(:,:,reg) = xlsread(filename_data, TAB.Reported, range{1});
    end
    
    range = strcat('L', num2str(5 + n + 2*m + n*m), ':', xlsColNum2Str(xlsColStr2Num({'L'})+ m - 1), num2str(4 + n + 3*m + n*m));
    prob_matrix = xlsread(filename_data, TAB.Reported, range{1})'; 
    B = 0; D_p = 0; sigma_p = 0; % Problem with no predictability !
    clear range;
         
    diary on
    display('   *************  Initial Parameters   *************  '); 
    display(A);
    display(var_cov);
    display(prob_matrix);
    diary off
    
    initial_parameters = Parameters_to_List(A, B, var_cov, prob_matrix, D_p, sigma_p);
    
    options = optimset('LargeScale','off','MaxFunEvals', 100000, 'MaxIter', 100000, 'TolFun',1e-10, 'TolX',1e-10); %configuration of the optimization variable
    
    display('entrada no otimizador');
    
    [final_parameters, f_abs_value, exitflag, output_structure, grad, hessian_matrix] = fminunc(@Objective_Function, initial_parameters, options);
            
    display('saida do otimizador');
    [A, B, var_cov, prob_matrix, D_p, sigma_p] = List_to_Parameters(final_parameters);
    
    ergodic_probabilities = Ergodic_Probabilities(m, prob_matrix');
    
    hessian_inverted = hessian_matrix^(-1);
    gradient = Delta_Method(final_parameters);
    
    % The standard errors of the means, volatility matrices terms and probabilities (the gradient matrix is to correct the fact the 
    % probabilities are indirectly estimated through the exp function):
    parameters_std_errors = sqrt(diag(gradient*hessian_inverted*gradient')); 
        
    % We had used the hessian inverted without the minus sign because the function minimized was -f (to maximize f, the
    % log-likelihood function).

    max_f_value = - f_abs_value;
    diary on
    display(exitflag);
    display(output_structure);
    
    display('   *************  Maximum Likelihood   *************  '); 
    display(max_f_value);
    
    display('   *************  Final Parameters   *************  '); 
    display(A);
    display(var_cov);
    display(prob_matrix);
    display(parameters_std_errors);
    
    display('   *************  Ergodic Probabilities   *************  '); 
    display(ergodic_probabilities); % Written with program A
    
    display('   *************  Probability Volatility Matrix   *************  '); 
    display(' TO BE WRITTEN '); % Written with program A

    
    diary off
    
% Writing the results in the correct workbook (using writetable):
    % Writing m-State Mean Returns
        T1 = table(A');
        local1 = strcat('C', num2str(4 + n));
        writetable(T1,filename_data,'Sheet',TAB.Parameters,'Range',local1,'WriteVariableName',false);
    % Writing m-State Var-Cov Matrix
        for reg =1:m 
           T2 = table(var_cov(:,:,reg));
           local2 = strcat('C', num2str(4 + m + reg*(n+1)));
           writetable(T2,filename_data,'Sheet',TAB.Parameters,'Range',local2,'WriteVariableName',false);
        end
    % Writing Monthly Transition Probabilities
        T3 = table(prob_matrix');
        local3 = strcat('C', num2str(5 + n + 2*m + n*m));
        writetable(T3,filename_data,'Sheet',TAB.Parameters,'Range',local3,'WriteVariableName',false);
    % Adjusting Excel Column Width
        T4 = table (' ',' ',' ',' '); 
        local4 = strcat('C', num2str(4 + n + 3*m + n*m + 1));  
        writetable(T4,filename_data,'Sheet',TAB.Parameters,'Range',local4,'WriteVariableName',false);
    clear T1 local1 T2 local2 T3 local3 T4 local4
    
    tm=toc
    display('   *************  *************  *************  ************* ************* ***** '); 
    display('   *************  *************  *************  ************* ************* ***** '); 
    display('   *************  Output Structure *************  '); 
    display(output_structure);
    display('   *************  *************  *************  Time in Minutes     ************* >>> '); 
    disp(datestr(datenum(0,0,0,0,0,tm),'HH:MM:SS'))
    format short
    display('   *************  *************  *************  Maximum Likelihood  ************* >>> '); 
    format long;
    display(max_f_value);
    display('   *************  Exit Flag   *************  '); 
    display(exitflag); 
    display('   *************  *************  *************  ************* ************* ***** '); 
    display('   *************  *************  *************  ************* ************* ***** '); 
    
    beep;
      
end